<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class UploadController extends Controller
{
    public function upload(Request $request)
    {

        if ($request->hasFile('file')) {
            $file = $request->file('file');
            $fileName = time().'.'.$file->getClientOriginalExtension();
            $filePath = $file->storeAs('uploads', $fileName, 'public');

            return response()->json(['success' => '文件上传成功', 'file_path' => $filePath]);
        }

        return response()->json(['error' => '没有文件被上传'], 400);
    }
}
